<template>
<!-- 列表 -->
<div class="stu">

    <mu-paper @click="go(i,indexs)" class="demo-paper" :style="stycs(indexs,index)" :z-depth="1" v-for="(i,indexs) in tabbox">{{txtlv(i)}}</mu-paper>

</div>
</template>
<script>
import {
  Notify
} from 'vant';
export default {
  name: 'home',
  components: {},
  computed: {
      txtlv(){//过滤。txt
          return (i)=> i.replace(".txt","");
      },
      stycs(){
          return (index,num)=>{
               if(index === num){
                   return {
                       'background':'red',
                       'color':'white'
                   }
               }
          }
      }
  },
  data() {
    return {
        tabbox:[],
        index:0
    }
  },
  methods: {
      go(i,index){
          this.$store.state.titletxt = this.txtlv(i);
          let query = this.$route.query.name+'/'+i;
          this.totxtnum(index);
          this.$router.push({path:'/do',query:{name:query}});
      },
    git_data() { //
      let pams = {
          name:this.$route.query.name
      }
      this.$get('/d/pat', pams).then(res => {
          if(res.code===200){
              this.tabbox = res.data;
              this.fuindex()
          }
      });
    },
      totxtnum(index){//存储书签
          if(localStorage.zj){
              let box = JSON.parse( localStorage.zj );
              let io = false;
              for(let i of box){
                  if(i.name === this.$route.query.name){
                      io = true
                      i.num = index
                      break
                  }else{
                      io = false
                  }
              }
              if(!io){
                  box.push({
                      name:this.$route.query.name,
                      num:index
                  });
              }
              localStorage.zj = JSON.stringify( box );
          }else{
              let box = [];
              box.push({
                  name:this.$route.query.name,
                  num:index
              });
              localStorage.zj = JSON.stringify( box );
          }
      },
      fuindex(){
          if(!localStorage.zj){return false;}
          let box = JSON.parse( localStorage.zj );
          for(let i of box){
              if(i.name === this.$route.query.name){
                  this.index = i.num;
                  break;
              }
          }
      },

  },
  mounted() {
      this.git_data();
      this.$store.state.btnnum = 0;
  }
}
</script>
<style scoped="scoped">
 .demo-paper{
     width:95%;
     height:1.33rem  /* 100/75 */;
     margin: 0.3rem auto;
     padding-left:0.5rem;
     line-height: 1.33rem;
 }

.stu {
  width: 100%;
  padding-top: 0.1rem;
}
</style>
